'''
Created on 02/11/2012

@author: GabrielBacelar
'''

class HW4Q1():
    '''
    classdocs
    '''
    
    def __init__(self):
        '''
        Constructor
        '''
        import ValueIteration
        self.valueIteration = ValueIteration.ValueIteration()
    
    def getHW4Q1(self):
        self.valueIteration.actions = ["CW","CCW"]
        self.valueIteration.nodes = ["A","B","C"]
        
        self.valueIteration.gama = 0.5
        
        """
        s     a     s'     T(s,a,s')     R(s,a,s')
        A     CW     B     0.6     0.0
        A     CW     C     0.4     2.0
        A     CCW     C     1.0     -2.0
        B     CW     C     1.0     -2.0
        B     CCW     A     0.6     0.0
        B     CCW     C     0.4     0.0
        C     CW     A     1.0     2.0
        C     CCW     A     0.4     0.0
        C     CCW     B     0.6     0.0
        """
        
        self.valueIteration.T,self.valueIteration.R = {},{}
        self.valueIteration.T[("A","CW","B")] = 0.6
        self.valueIteration.R[("A","CW","B")] = 0.0
        self.valueIteration.T[("A","CW","C")] = 0.4
        self.valueIteration.R[("A","CW","C")] = 2.0
        self.valueIteration.T[("A","CCW","C")] = 1.0
        self.valueIteration.R[("A","CCW","C")] = -2.0
        self.valueIteration.T[("B","CW","C")] = 1.0
        self.valueIteration.R[("B","CW","C")] = -2.0
        self.valueIteration.T[("B","CCW","A")] = 0.6
        self.valueIteration.R[("B","CCW","A")] = 0.0
        self.valueIteration.T[("B","CCW","C")] = 0.4
        self.valueIteration.R[("B","CCW","C")] = 0.0
        self.valueIteration.T[("C","CW","A")] = 1.0
        self.valueIteration.R[("C","CW","A")] = 2.0
        self.valueIteration.T[("C","CCW","A")] = 0.4
        self.valueIteration.R[("C","CCW","A")] = 0.0
        self.valueIteration.T[("C","CCW","B")] = 0.6
        self.valueIteration.R[("C","CCW","B")] = 0.0
        
        self.valueIteration.V = {}
        self.valueIteration.Vstar = {}
        
        self.valueIteration.V["A"] = 1.2
        self.valueIteration.V["B"] = 0.64
        self.valueIteration.V["C"] = 2.4
        
        self.valueIteration.Vstar["A"] = 1.692
        self.valueIteration.Vstar["B"] = 1.077
        self.valueIteration.Vstar["C"] = 2.846
        
    def resolveHW4Q1(self):
        self.getHW4Q1()
        
        node = "A"
        print node, self.valueIteration.getValueIteration(node)
        
        node = "B"
        print node, self.valueIteration.getValueIteration(node)
        
hw4q1 = HW4Q1()
hw4q1.resolveHW4Q1()
        
